package com.baidu.customview.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

import java.util.ArrayList;

/**
 * Created by imagine on 2015/10/12.
 */
public abstract class MBaseAdapter<T> extends BaseAdapter {
    private ArrayList<T> list;
    private BaseAdapterCallback callback;
    private LayoutInflater inflater;

    public MBaseAdapter(ArrayList<T> list, Context context, BaseAdapterCallback callback) {
        this.list = list;
        this.inflater = LayoutInflater.from(context);
        this.callback = callback;
    }

    @Override
    public int getCount() {
        return list == null ? 0 : list.size();
    }

    @Override
    public Object getItem(int position) {
        return list == null ? null : list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        return callback.getView(position, convertView, parent, inflater);
    }

    public interface BaseAdapterCallback {
        View getView(int position, View convertView, ViewGroup parent, LayoutInflater inflater);
    }
}
